function [ results_fnames ] = osl_run_first_level( oat )

% [ results_fnames ] = osl_run_first_level( oat )
%
% takes in an OAT, which needs to be setup by calling oat=osl_setup_oat(S), struct
% and runs first level analysis
%
% This function should normally be called using osl_run_oat(oat);
%
% MWW 2011

global OSLDIR;

if(~oat.first_level.is_epoched),    

    if(~oat.first_level.hmm_do_glm_statewise)
        results_fnames = osl_run_first_level_continuous(oat); % Do time-wise analysis        
    else
        switch lower(oat.source_recon.type)
            case 'scalar'
                results_fnames = osl_run_first_level_continuous_state(oat); % Do time-wise analysis state-wise        
            case 'vector'   
                
                if(~isempty(oat.first_level.connectivity_seed_mni_coord)),
                    results_fnames = osl_run_first_level_continuous_state_vector_seed(oat); % Do time-wise analysis state-wise        
                else
                    results_fnames = osl_run_first_level_continuous_state_vector(oat); % Do time-wise analysis state-wise        
                end;
        end;
    end;
else
    
    if(isfield(oat.first_level,'connectivity_seed_mni_coord') && ~isempty(oat.first_level.connectivity_seed_mni_coord)),    
        error('Currently not supported');
        results_fnames = osl_run_first_level_epoched_connectivity(oat); 
    else
        
        if(~oat.first_level.hmm_do_glm_statewise)
            results_fnames = osl_run_first_level_epoched(oat); % Do time-wise analysis        
        else
            results_fnames = osl_run_first_level_epoched_state(oat); % Do time-wise analysis state-wise        
        end;
    end;
end;
